package com.ktjy.ch15.config;

import com.ktjy.ch15.config.SpringConfig;
import com.ktjy.ch15.config.SpringMvcConfig;
import jakarta.servlet.MultipartConfigElement;
import jakarta.servlet.ServletRegistration;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

public class WebConfig extends AbstractAnnotationConfigDispatcherServletInitializer {
    //加载spring配置累
    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[]{SpringConfig.class};
    }
    //加载spring mvc的配置类
    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{SpringMvcConfig.class};
    }
    //设置spring mvc前端控制器 拦截的路劲
    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }

    @Override
    protected void customizeRegistration(ServletRegistration.Dynamic registration) {
        // 配置multipart设置
        registration.setMultipartConfig(
                new MultipartConfigElement(
                        null,                // 临时文件存储位置
                        5 * 1024 * 1024,    // 最大文件大小 (5MB)
                        20 * 1024 * 1024,   // 最大请求大小 (20MB)
                        0                   // 文件大小阈值
                )
        );
    }
}
